from collections import Counter

class Solution:
    def getHint(self, secret: str, guess: str) -> str:
        flag = Counter()
        used = set()
        x, y = 0, 0
        for i in range(len(secret)):
            if secret[i] == guess[i]:
                x += 1
                used.add(i)
            else:
                flag.update(secret[i])

        for i in range(len(guess)):
            if i in used:
                continue

            if guess[i] in flag:
                flag.subtract(guess[i])
                if flag[guess[i]] == 0:
                    flag.pop(guess[i])
                y += 1

        return f"{x}A{y}B"
